library("unsupervisedMicroarray")
source("./generatePReducersList.R")
data(brain)
data(leukemia)
data(carcinoma)
data(colon)

setList <-list(
		brain,leukemia,carcinoma,colon
)
#registerDoMC(cores=6)
reducers <- generatePReducersListComp()
directory="./visSets"
dir.create(directory)
width=1024
height=1024
registerDoMC(cores=6)

for(set in 1:length(setList)){
	dir.create(paste(directory,"/",setList[[set]]$Name,sep=""))
	print(paste("SET: ",setList[[set]]$Name,sep="" ))
	
	for(reducer in 1:length(reducers)){#1:length(reducers)
		print(paste("RED: ",get_description(reducers[[reducer]]),sep="")) 	
		fname = paste(directory,"/",setList[[set]]$Name,"/",get_description(reducers[[reducer]]),".png",sep="")
		fname = chartr(" ;:","___",fname)
		tmpSetX <-setList[[set]]$X
		#reduce
		print("reduce")
		tmpSetX <-computeList(reducers[[reducer]],setList[[set]])$X
		
		print(paste("TMS SET DIM: ",dim(tmpSetX)))	
		print("calculate min max")
		xmin <-min(tmpSetX[,1])
		xmax <-max(tmpSetX[,1])
		
		ymin <-min(tmpSetX[,2])
		ymax <-max(tmpSetX[,2])
		
		colors <-rainbow(length(unique(setList[[set]]$Y)))
		print("plot")
		png(filename=fname, height=width, width=height,bg="white")
		plot(NULL,xlim=c(xmin,xmax),ylim=c(ymin,ymax),col.lab=rgb(0,0,0),ann=FALSE)
			for(i in unique(setList[[set]]$Y) ){
				points(tmpSetX[setList[[set]]$Y==i,],pch=i,col=colors[i])
			}
			
		
		ptype <-unique(setList[[set]]$Y)	
		legend(xmin, ymax, unique(setList[[set]]$Y), col=colors, pch=ptype, title="Class")
		title(paste(setList[[set]]$Name,"\n",get_description(reducers[[reducer]]),sep=""))
		grid()
		dev.off()
		
	}
}